//
//  AppDelegate.m
//  WristWatch
//
//  Created by dllo on 15/10/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "MZYHeader.h"
#import "UMSocial.h"
#import "MobClick.h"
#import "MZYleadViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc {
    [_window release];
    [_tab release];
    
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    MZYheadTableViewController *miVC = [[MZYheadTableViewController alloc] init];
    UINavigationController *miNaVC = [[UINavigationController alloc] initWithRootViewController:miVC];
    miNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"资讯" image:[UIImage imageNamed:@"information"] tag:1000] autorelease];
    
    MZYBrandViewController *mbVC = [[MZYBrandViewController alloc] init];
    UINavigationController *mbNaVC = [[UINavigationController alloc] initWithRootViewController:mbVC];
    mbNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"品牌" image:[UIImage imageNamed:@"brand"] tag:1001] autorelease];
    
    MZYPictureViewController *mpVC = [[MZYPictureViewController alloc] init];
    UINavigationController *mpNaVC = [[UINavigationController alloc] initWithRootViewController:mpVC];
   mpNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"图鉴" image:[UIImage imageNamed:@"picture"] tag:1002] autorelease];
    
    MZYMyViewController *mmVC = [[MZYMyViewController alloc] init];
    UINavigationController *mmNaVC = [[UINavigationController alloc] initWithRootViewController:mmVC];
    mmNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"展示" image:[UIImage imageNamed:@"display"] tag:1003] autorelease];
    
    MZYSetUpViewController *msuVC = [[MZYSetUpViewController alloc] init];
    UINavigationController *msuNaVC = [[UINavigationController alloc] initWithRootViewController:msuVC];
    msuNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"my"] tag:1004] autorelease];
    
    self.tab = [[UITabBarController alloc] init];
    self.tab.viewControllers = @[miNaVC, mbNaVC,mpNaVC, mmNaVC, msuNaVC];
    
    self.window.rootViewController = self.tab;
    
    // 设置外观tabbar
    self.tab.tabBar.translucent = NO;
    
    // 选中后的颜色
    self.tab.tabBar.tintColor = [UIColor blackColor];
//    [[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:56 / 255.0 green:63 / 255.0 blue:70 / 255.0 alpha:1]];
    [_tab release];
    [mbNaVC release];
    [mbVC release];
    [miNaVC release];
    [miVC release];
    [mpNaVC release];
    [mpVC release];
    [mmNaVC release];
    [mmVC release];
    [msuNaVC release];
    [msuVC release];

    // 友盟分享
    [UMSocialData setAppKey:@"563ac022e0f55a5cc9000192"];

    
    // 统计
    [MobClick startWithAppkey:@"563ac022e0f55a5cc9000192" reportPolicy:BATCH   channelId:@"Web"];
    [MobClick profileSignInWithPUID:@"563ac022e0f55a5cc9000192" provider:@"WB"];
    
    // 引导页
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *key = (NSString *)kCFBundleVersionKey;
    NSString *sandBoxVersion = [defaults valueForKeyPath:key];
    // 获取当前版本号
    NSDictionary *md = [NSBundle mainBundle].infoDictionary;
    NSString *currentVersion = md[key];
    if ([currentVersion compare:sandBoxVersion] == NSOrderedDescending)
    {
        NSLog(@"ss ");
        // 存储当前版本号
        [defaults setObject:currentVersion forKey:key];
        //锁定当前线程
        [defaults synchronize];
        // 第一次使用当前版本  显示引导页
        [self showGuidePage];
    }
    else
    {
        NSLog(@"sssdsf");
        // 不是第一次使用当前版本  显示主页面
        [self.window setRootViewController:self.tab];
        
    }
    

    return YES;
}
// 引导页方法
- (void)showGuidePage
{
    MZYleadViewController *con = [[MZYleadViewController alloc] init];
    [self.window setRootViewController:con];
    [con release];
}
// 假夜间模式
- (void)change
{
    if (self.window.alpha == 0.5) {
        self.window.alpha = 1;
    } else {
        self.window.alpha = 0.5;
    }
}

// 不允许横屏
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
